package com.xyp.demo.service.impl;

import com.xyp.demo.dao.CityMapper;
import com.xyp.demo.model.City;
import com.xyp.demo.model.CityExample;
import com.xyp.demo.service.ICityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xyp
 * @date 2019-11-05 10:35
 * @description
 * @version: 1.0
 */
@Service
public class CityServiceImpl implements ICityService {
    @Autowired
    private CityMapper cityMapper;

    @Override
    public City getCityByName(String name) {
        CityExample example = new CityExample();
        example.createCriteria().andNameEqualTo(name);
        List<City> cityList = cityMapper.selectByExample(example);
        return CollectionUtils.isEmpty(cityList) ? null : cityList.get(0);
    }
}
